#include"comm.h"
//客户端：
//1.以写入方式打开管道
//2.以读取方式打开要被拷贝的文件
//3.将该文件的内容写入到管道当中
//最后要关闭这两个文件描述符
int main()
{
    int fd = open(MY_FIFO,O_WRONLY);
    if(fd<0)
    {
        perror("open:");
        exit(1);
    }
    int read_fd = open("./file.txt",O_RDONLY);
    while(1)
    {
        char buff[128] = {0};
        memset(buff,0,sizeof(buff));//buf[0] = 0
        ssize_t n = read(read_fd,buff,sizeof(buff));
        //若期望写入sizeof(buff)则最后会出现乱码！！！
        if(n > 0) write(fd,buff,n); //注意：这里期望写入的字符个数是读取的字符个数！！！
        else if(n == 0)
        {
            printf("read file over...\n");
            break;
        }
        else
        {
            perror("read:");
            break;
        }
    }
    close(fd);
    close(read_fd);
    return 0;
}
